<template>
    <div :style="{padding: '24px', minHeight: '480px', background: '#fff'}">
        <el-row :gutter="10">
            <el-col :span="4" v-for="ware in warehouses" :key="ware.id">
                <div class="warehouse-warp">
                    <div class="ware-info">
                        {{ware.warehouseName}}
                    </div>
                    <div class="ware-info">
                        {{ware.linkMan}},{{ware.phone}}
                    </div>
                    <div class="ft-info">
                        <template v-if="ware.state==1">
                            <el-tag type="success" effect="dark">
                                已开通
                            </el-tag>
                            <span style="float:right;margin-top:5px;" @click="close(ware)">关闭<i class="el-icon-d-arrow-right"></i></span>
                        </template>
                        <template v-else>
                            <el-tag type="info" effect="dark">
                                暂未开通
                            </el-tag>
                            <span style="float:right;margin-top:5px;" @click="toLoginOrSign(ware)">点击开通<i class="el-icon-d-arrow-right"></i></span>
                        </template>
                    </div>
                </div>
            </el-col>
        </el-row>
    </div>
</template>
<script>
import Constants from "@/utils/constants"
import api from '@/api/api'
export default {
    name: 'Login',
    data() {
        return {
            loading: false,
            warehouses: [],
            loginOk: false,

        }
    },
    mounted: function() {
        this.opened();
    },
    watch: {

    },
    methods: {
        opened: function() {
            this.loading = true;
            this.$http.post("/merchant/getall.do", {}).then(res => {
                this.loading = false;
                if (res.status == 0) {
                    this.warehouses = res.obj;
                } else {
                    this.errorMessage(res.info);
                }
            }, res => {
                this.errorMessage("系统异常！");
                this.loading = false;
            });
        },
        close: function(ware) {
        	this.showLoading();
            this.$http.post("/merchant/closeWare.do", {
                warehouseId: ware.id
            }).then(res => {
                this.hideLoading();
                if (res.status == 0) {
                    this.opened();
                } else {
                    this.errorMessage(res.info);
                }
            }, res => {
                this.errorMessage("系统异常！");
                this.hideLoading();
            });
        },
        showDialog: function() {
            this.loginOk = true;
        },
        toLoginOrSign: function(ware) {
            //
            this.showLoading();
            this.$http.post("/merchant/change.do", {
                warehouseId: ware.warehouseId
            }).then(res => {
                this.hideLoading();
                if (res.status == 0) {
                    this.opened();
                } else {
                    this.errorMessage(res.info);
                }
            }, res => {
                this.errorMessage("系统异常！");
                this.hideLoading();
            });
        }

    },
    computed: {


    },
    components: {

    }
}
</script>
<style scoped>
.warehouse-warp {
    padding: 10px 10px 5px 10px;
    border-radius: 5px;
    border: 1px solid #cecece;
    cursor: pointer;
}

.warehouse-warp :hover {}

.warehouse-warp .ft-info {
    padding-top: 5px;
    padding-bottom: 5px;
    border-top: 1px solid #cecece;
}
</style>